package myJs.implicits

import scala.scalajs.js
import scala.scalajs.js.JSON
import myJs.Implicits._

/**
 * Created by Administrator on 2020/1/16
 */
trait MyStringTool {

  type JArJDJAn = js.Array[js.Dictionary[js.Any]]
  type JArJDS = js.Array[js.Dictionary[String]]
  type JDJAn = js.Dictionary[js.Any]
  type JDS = js.Dictionary[String]
  type JArS = js.Array[String]

  implicit class MyString(v: String) {

    def toJDS = {
      JSON.parse(v).toJDS
    }

    def toJDJAn = {
      JSON.parse(v).toJDJAn
    }

    def toJArJDS = {
      JSON.parse(v).toJArJDS
    }

    def toJArS = {
      JSON.parse(v).toJArS
    }

    def toJArJDJAn = {
      JSON.parse(v).toJArJDJAn
    }

    def headLower = {
      if (v == null || v.length == 0 || !v.charAt(0).isUpper) v
      else v.updated(0, v.charAt(0).toLower)
    }

    def nonBlank = {
      v.trim.nonEmpty
    }

    def isBlank = {
      !nonBlank
    }

  }

}
